"""
    def test_basic_addition(self):
        #Tests that 1 + 1 always equals 2.
        self.failUnlessEqual(1 + 1, 2)
"""

from django.test import TestCase
from models import Idea, Content

class IdeaTest(TestCase):
    """
    IdeaTest tests the functionality of the Idea model.
    
    Ideas are structured in a tree format so the IdeaTest class performs
    sanity checks on the creation of new ideas as well as checks on the
    maintenance of the tree structure.
    """
    def setUp(self):
        # Create a generic content objects for use in testing.
        self.root_content = Content.objects.create()
        self.parent_content = Content.objects.create()
        self.uncle_content = Content.objects.create()
        self.child_content = Content.objects.create()
        self.sibling_content = Content.objects.create()
        
        self.root = Idea.objects.create(content=self.root_content) #Creates a root idea with an anonymous author
        self.parent = Idea.objects.create(parent=self.root, content=self.parent_content) #Creates a parent idea
        self.uncle = Idea.objects.create(parent=self.root, content=self.uncle_content) #Creates an uncle
        self.child = Idea.objects.create(parent=self.parent, content=self.child_content) #Creates an uncle
        self.sibling = Idea.objects.create(parent=self.parent, content=self.sibling_content) #Creates an uncle
        
    def test_creation_sanity(self):
        """
        Checks to ensure that all objects were created as expected. All contents are correct.
        
        1. Checks to ensure that the contents are as specified.
        """
        #1
        self.failUnlessEqual(self.root.content, self.root_content);
        self.failUnlessEqual(self.parent.content, self.parent_content);
        self.failUnlessEqual(self.uncle.content, self.uncle_content);
        self.failUnlessEqual(self.child.content, self.child_content);
        self.failUnlessEqual(self.sibling.content, self.sibling_content);
        
    def test_children(self):
        """
        Tests to ensure that child nodes are returned properly.
        """
        self.failUnlessEqual(set(self.root.children),set([self.parent, self.uncle]))
        self.failUnlessEqual(set(self.parent.children),set([self.child, self.sibling]))
        self.failIf(self.uncle.children)
        self.failIf(self.child.children)
        self.failIf(self.sibling.children)
        
    def test_siblings(self):
        """
        Tests to ensure that sibling nodes are returned properly.
        """
        self.failIf(self.root.siblings)
        self.failUnlessEqual(set(self.parent.siblings),set([self.uncle]))
        self.failUnlessEqual(set(self.uncle.siblings),set([self.parent]))
        self.failUnlessEqual(set(self.child.siblings),set([self.sibling]))
        self.failUnlessEqual(set(self.sibling.siblings),set([self.child]))
    
    def test_parent(self):
        """
        Parent nodes are returned properly.
        """
        self.failIf(self.root.parent)
        self.failUnlessEqual(self.parent.parent,self.root)
        self.failUnlessEqual(self.uncle.parent,self.root)
        self.failUnlessEqual(self.child.parent,self.parent)
        self.failUnlessEqual(self.sibling.parent,self.parent)
        
class ConnectionTest(TestCase):
    """
    ConnectionTest tests the functionality of the Connection model
    """
    def setUp(self):
        # Create a generics objects for use in testing.
        self.root_content = Content.objects.create()
        self.parent_content = Content.objects.create()
        self.uncle_content = Content.objects.create()
        self.child_content = Content.objects.create()
        self.cousin_content = Content.objects.create()
        self.conn_content = Content.objects.create()
        
        self.root = Idea.objects.create(content=self.root_content) #Creates a root idea with an anonymous author
        self.parent = Idea.objects.create(parent=self.root, content=self.parent_content) #Creates a parent idea
        self.uncle = Idea.objects.create(parent=self.root, content=self.uncle_content) #Creates an uncle
        self.child = Idea.objects.create(parent=self.parent, content=self.child_content) #Creates an uncle
        self.cousin = Idea.objects.create(parent=self.uncle, content=self.cousin_content) #Creates an uncle
        
    def test_connection_sanity(self):
        """
        Connected items are listed as connected
        """
        self.failIf(self.root.connections)
        self.failIf(self.parent.connections)
        self.failIf(self.uncle.connections)
        self.failIf(self.child.connections)
        self.failIf(self.cousin.connections)
        
        # Connect cousins
        self.child.connection_set.add(self.cousin)
        
        # Cousins are connected
        self.failIf(self.root.connections)
        self.failIf(self.parent.connections)
        self.failIf(self.uncle.connections)
        self.failUnlessEqual(set(self.child.connections), set([self.cousin]))
        self.failUnlessEqual(set(self.cousin.connections), set([self.child]))
        
class ContentTest(TestCase):
    """
    ContentTest tests the functionality of the Content model
    """
    pass